# To build:
#    docker build -t lvgl .
#
# To see how to do GUI forwarding in macOS:
#     https://cntnr.io/running-guis-with-docker-on-mac-os-x-a14df6a76efc
#
# To do GUI forwarding on linux, the following may work (easiest method, but unsafe)
#     xhost + && docker run --network=host --env DISPLAY=$DISPLAY lvgl

FROM ubuntu:20.04 AS builder
RUN sed -i 's/archive/cn.archive/g' /etc/apt/sources.list \
  && apt-get update \
  && apt-get install -y tzdata \
  && apt-get install -y build-essential cmake mesa-utils libgl1-mesa-glx x11-apps libavdevice-dev libavfilter-dev libavresample-dev libfreetype-dev libjpeg-dev libpng-dev libsdl2-image-dev

COPY . /mnt/lvgl
RUN cd /mnt/lvgl && cmake -Bb -DLV_USE_DRAW_SDL:BOOL=ON -DLV_USE_FFMPEG:BOOL=ON -DLV_USE_FREETYPE:BOOL=ON -DLV_USE_LIBJPEG_TURBO:BOOL=ON -DLV_USE_LIBPNG:BOOL=ON -DCMAKE_BUILD_TYPE:STRING=Release . && cmake --build b -j8 -t install

FROM ubuntu:20.04
RUN sed -i 's/archive/cn.archive/g' /etc/apt/sources.list \
  && apt-get update \
  && apt-get install -y tzdata \
  && apt-get install -y mesa-utils libgl1-mesa-glx x11-apps libavdevice58 libavfilter7 libavresample4 libfreetype6 libjpeg8 libpng16-16 libsdl2-image-2.0-0 \
  && apt-get clean \
  && rm -rf /var/lib/apt/lists/*
COPY --from=builder /usr/local /usr/local
ENV DISPLAY=:0
CMD ["/usr/local/bin/main"]
